package shayu.order.web;

import com.alibaba.fastjson.JSONObject;
import com.alipay.api.domain.AlipayAccount;
import com.alipay.api.request.AlipayTradePagePayRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import shayu.order.service.OrderService;
import shayu.order.vo.PayVo;

@Controller
public class PayWebController {


    @Autowired
    OrderService orderService;

    @ResponseBody
    @GetMapping("/payOrder")
    public String payOrder(@RequestParam("orderSn") String orderSn) {

        PayVo payVo = orderService.getOrderPay(orderSn);
        AlipayTradePagePayRequest alipayTradePagePayRequest = new AlipayTradePagePayRequest();
        JSONObject bizContent = new JSONObject();
        //商户订单号，商家自定义，保持唯一性
        bizContent.put("out_trade_no", payVo.getOut_trade_no());
        //支付金额，最小值0.01元
        bizContent.put("total_amount", payVo.getTotal_amount());
        //订单标题，不可使用特殊符号
        bizContent.put("subject", payVo.getSubject());
        System.out.println(bizContent);
        return "redirect:pay";
    }
}
